package com.gack.business.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.gack.business.model.Permission;

@Repository
public interface PermissionRepository extends JpaRepository<Permission, String>, JpaSpecificationExecutor<Permission>{

	@Query("from Permission where id in "
			+ "(select permissionId from RolePermission where roleId in "
			+ "(select roleId from UserEnterpriseDepartmentRole where userId=:userId and enterpriseId=:enterpriseId))")
	List<Permission> findByUserIdAndEnterpriseId(@Param("userId") String userId, @Param("enterpriseId") String enterpriseId);
	
	@Query("select roleId from Permission where roleId = :roleId")
	List<String> findUrlByRoleId(@Param("roleId")String roleId);
	
}
